package cn.skyclass.utils
{
	import mx.utils.ObjectUtil;
	
	/**
	 * flex 语言工具类
	 */
	public class FlexUtil
	{
		/**
		 * get the class full name of specified object, including package name
		 * eg: cn.skyclass.bean::BaseBean
		 */
		public static function getQualifiedClassName(obj:Object):String{
			var claInfo:Object = ObjectUtil.getClassInfo(obj);	
			return claInfo["name"];
		}
		
		/**
		 * get the class short name of specified object, without package name
		 * eg: BaseBean
		 */
		public static function getClassShortName(obj:Object):String{
			var claInfo:Object = ObjectUtil.getClassInfo(obj);	
			var fullName:String = claInfo["name"];
			var shortName:String = fullName.substring(fullName.lastIndexOf("::") + 2);
			return shortName;
		}		

		/**
		 * trace the code position info
		 */
		public static function tracePosition(target:Object, 
			fileName:String="", funcName:String="", lineNum:int=-1):void{
				
			var claInfo:Object = ObjectUtil.getClassInfo(target);				
			trace("positon info:: ", " class name:", claInfo["name"], ", target:", target,
				", file path:", fileName, ", method:", funcName, ", line:", lineNum);			
		}
		
		/**
		 * abstract method simulator, to avoid invoke the unimplement method
		 */
		public static function traceUnimplementedMethod(methodName:String, target:Object=null):void{
			var claInfo:Object = ObjectUtil.getClassInfo(target);				
			var msg:String = "warn: an unimplemented method has been called.";
			msg += " it should be overridden in subclasses.";
			msg += " method name:" + methodName + ", in class " + claInfo["name"];

			trace(msg);
			new Log4Flex().info(msg);
		}		
	}
}